<?php
/**
 * Created by PhpStorm.
 * User: s.utkin
 * Date: 30.04.2015
 * Time: 17:50
 */

namespace Resources;


use Resources\Config\PackagesConfig;

class Package {

	public static function getItemsInfo($package, $fileType, $withExternal = true)
	{
		$packageClass = PackagesConfig::get($package);
		if ($packageClass == null) {
			return [];
		}

		$items = $packageClass::get($fileType);
		if ($items == null) {
			return [];
		}

		return array_filter($items, function($value) use ($withExternal) {
				return $withExternal || !isset($value['external']) || !$value['external'];
			});
	}

	public static function getPositions($package, $fileType, $withExternal = true)
	{
		$positions = [];
		$items = static::getItemsInfo($package, $fileType, $withExternal);
		foreach ($items as $item) {
			$positions[$item['position']] = true;
		}

		return array_keys($positions);
	}
} 